package uic.easyface;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Bitmap.Config;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {

	int mGalleryItemBackground;
	private Context mContext;
	private Integer[] mImageIds;
	private ImageView[] mImages;

	public ImageAdapter(Context c, Integer[] ImageIds) {
		mContext = c;
		mImageIds = ImageIds;
		mImages = new ImageView[mImageIds.length];
	}

	public boolean createReflectedImages() {
		int index = 0;

		for (int imageId : mImageIds) {
			Bitmap originalImage = BitmapFactory.decodeResource(
					mContext.getResources(), imageId);

			Matrix matrix = new Matrix();
			matrix.preScale(1, -1);

			Bitmap tempBitmap = Bitmap.createBitmap(originalImage.getWidth(),
					originalImage.getHeight(), Config.ARGB_8888);
			Canvas canvas = new Canvas(tempBitmap);

			canvas.drawBitmap(originalImage, 0, 0, null);

			ImageView imageView = new ImageView(mContext);
			imageView.setImageBitmap(tempBitmap);
			imageView.setLayoutParams(new GalleryFlow.LayoutParams(180, 240));

			mImages[index++] = imageView;
		}
		return true;
	}

	public int getCount() {
		return mImageIds.length;
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		return mImages[position];
	}

	public float getScale(boolean focused, int offset) {
		return Math.max(0, 1.0f / (float) Math.pow(2, Math.abs(offset)));
	}

}
